package com.chenss.dragonser.view;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface.OnKeyListener;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.chenss.dragonser.R;
import com.chenss.dragonser.listener.OnMyDialogOneListener;
import com.chenss.dragonser.utils.WidgetTools;

/**
 * 只有一个选项的弹框
 * 
 */
public class XDialogOne {
	OnMyDialogOneListener oneListener;
	public XDialogOne(OnMyDialogOneListener oneListener) {
		this.oneListener=oneListener;
	}
	public void showOneDialog(Context context,String msg, String btn1, String title,final int tag) {
		// TODO Auto-generated method stub
		final Dialog dialog = new Dialog(context, R.style.Dialog_image);
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
			dialog.setContentView(R.layout.xdg_one_bt);
		WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
		TextView textView = (TextView) dialog.findViewById(R.id.text_message);
		TextView tv_title = (TextView) dialog.findViewById(R.id.tv_title);
		Button btn_one = (Button) dialog.findViewById(R.id.btn_one);

		if (TextUtils.isEmpty(title)) {
			tv_title.setVisibility(View.GONE);
		} else {
			WidgetTools.setText(tv_title, title);
		}
		WidgetTools.setText(textView, msg);
		WidgetTools.setText(btn_one, btn1);

		Window dialogWindow = dialog.getWindow();
		dialogWindow.setGravity(Gravity.CENTER);
		dialog.show();
		dialog.getWindow().setAttributes(params);

		btn_one.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				dialog.dismiss();
				oneListener.onSubmitClick(tag);
			}
		});

	}
	public void showOneDialog2(Context context,String msg, String btn1, String title,final int tag,OnKeyListener keylistener) {
		// TODO Auto-generated method stub
		final Dialog dialog = new Dialog(context, R.style.Dialog_image);
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
			dialog.setContentView(R.layout.xdg_one_bt);
			
			dialog.setCancelable(false);
			dialog.setOnKeyListener(keylistener);
			
		WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
		TextView textView = (TextView) dialog.findViewById(R.id.text_message);
		TextView tv_title = (TextView) dialog.findViewById(R.id.tv_title);
		Button btn_one = (Button) dialog.findViewById(R.id.btn_one);

		if (TextUtils.isEmpty(title)) {
			tv_title.setVisibility(View.GONE);
		} else {
			WidgetTools.setText(tv_title, title);
		}
		WidgetTools.setText(textView, msg);
		WidgetTools.setText(btn_one, btn1);

		Window dialogWindow = dialog.getWindow();
		dialogWindow.setGravity(Gravity.CENTER);
		dialog.show();
		dialog.getWindow().setAttributes(params);

		btn_one.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				dialog.dismiss();
				oneListener.onSubmitClick(tag);
			}
		});

	}
}
